package queen;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;

public class Graph {
    private ArrayList<String> vertexList;//存储顶点的集合
    private int[][] edges;//存储各点对应的邻接点的矩阵
    private int numofEdges;//表示变的数目

    public static void main(String[] args) {
        int n=5; //结点个数
        String vartextValue[] = {"A","B","C","D","E"};
        //创建图对象
        Graph graph = new Graph(5);
        //循环添加顶点
        for (String s : vartextValue) {
            graph.insertVertex(s);

        }
        //添加边 A-B A-C B-C B-D B-E
        graph.insertEdge(0,1,1);//A-B
        graph.insertEdge(0,2,1);//A-B
        graph.insertEdge(1,2,1);//A-B
        graph.insertEdge(1,3,1);//A-B
        graph.insertEdge(1,4,1);//A-B

        graph.show();

    }

    //构造器
    public Graph(int n) {
        //初始化矩阵和vertexList
        edges = new int[n][n];
        vertexList = new ArrayList<String>(n);
        numofEdges = 0;

    }
    //插入结点
    public void insertVertex(String vartext) {
        vertexList.add(vartext);
    }
    //添加边
    //v1 v2表示结点下标 weight是否直接相连接
    public void insertEdge(int v1, int v2 , int weight){
        edges[v1][v2]=weight;
        edges[v2][v1]=weight;
        numofEdges++;

    }
    //返回结点个数
    public int getNumOfVertex(){
        return vertexList.size();
    }
    //得到边的数目
    public int getNumofEdges(){
        return numofEdges;
    }
    //返回结点i(下标)对应的数据 0-> 'A'
    public String getValueByIndex(int i){
        return vertexList.get(i);
    }
    //返回v1和v2的权值
    public int getWeight(int v1,int v2){
        return edges[v1][v2];
    }
    //显示图
    public  void show(){
        for (int[] link : edges) {
            System.out.println(Arrays.toString(link));
        }

    }

    private void bfs(boolean[] isvisited,int i){
        int u;//表示队列的头节点的下标
        int w;//邻接节点下标
        //队列，结点访问的顺序
        LinkedList queen = new LinkedList();
        //访问结点，输出结点信息
        System.out.println(getValueByIndex(i)+"=>");
        isvisited[i]=true;
        //将结点加入队列
        queen.addLast(i);
        while (! queen.isEmpty()){
            //取出队列头节点下标
            u = (int) queen.removeFirst();
            //得到第一个邻结点下标


        }



    }
}
